//
//  WriteInfoViewController.m
//  DA_V
//
//  Created by 周季阳 on 15/4/28.
//  Copyright (c) 2015年 zhouhai. All rights reserved.
//

#import "WriteInfoViewController.h"
#import "InterFace.h"
#import "UIViewAdditions.h"
#import "ApplyForSuccessController.h"
#import "YoungAllData.h"
#import "GMDCircleLoader.h"

@interface WriteInfoViewController ()<UITextFieldDelegate,UITextViewDelegate,UIPickerViewDataSource,UIPickerViewDelegate,YoungDelegate,UITextViewDelegate>
{
    UITextField *nameTextField;
    UITextField *mobileTextField;
    UITextField *weChatTextField;
    UITextView *addressTextView;
    UITextField *loginTextField;
    
    UIPickerView *_picker;
    NSArray *pickerArray;
    
    NSInteger _select;//选择
    UILabel *label1;
    UILabel *label2;
    UILabel *label3;
    
    UIButton *shengBtn;
    UIButton *shiBtn;
    UIButton *quBtn;
    UIButton *zPickerBtn;
    
    UIScrollView *_scrollview;
   
}
@property(nonatomic,retain)NSString *zPID;
@property(nonatomic,retain)NSString *zCID;
@property(nonatomic,retain)NSString *zzCID;
@property(nonatomic,retain)NSMutableArray *zProvince;
@property(nonatomic,assign)NSInteger zIndex;
@end
#define Province 0 //省
#define City 1  //市
#define Qu 2   //区

@implementation WriteInfoViewController
@synthesize zProvince,zPID,zCID,zzCID,levelNumber,zZhengJianIndex,zCityIndex,zProvinceIndex,zIndex;

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [self colorWithHexString:@"#F5F5F5"];
    [self initNav];
    navTitle.text = @"填写信息";
    [self initUI];
    zPID = @"0";
    zCID = @"0";
    zProvinceIndex = 0;
    zCityIndex = 0;
    zZhengJianIndex = 0;
    
    //用来监视键盘的退出
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWillHide)
                                                 name:UIKeyboardWillHideNotification
                                               object:nil];
}

#pragma mark - 返回
-(void)clickBackBtn{
    [self.navigationController popViewControllerAnimated:YES];
}
#pragma mark - initUI
-(void)initUI{
    _scrollview = [[UIScrollView alloc]initWithFrame:CGRectMake(0, navView.bottom, SCREEN_WIDTH, SCREEN_HEIGHT)];
    _scrollview.contentSize = CGSizeMake(SCREEN_WIDTH, SCREEN_WIDTH*1.8);
    [self.view addSubview:_scrollview];
    UIView *backgroundView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT*0.8)];
    backgroundView.backgroundColor = [UIColor whiteColor];
    backgroundView.userInteractionEnabled = YES;
    [_scrollview addSubview:backgroundView];
    
    UIImageView *loginPwdB = [[UIImageView alloc] initWithFrame:CGRectMake(10,20, SCREEN_WIDTH-20, SCREEN_HEIGHT*0.07)];
    //loginPwdBG.image = [UIImage imageNamed:@"updatepassword_03"];
    loginPwdB.backgroundColor = [UIColor whiteColor];
    loginPwdB.layer.borderColor = [UIColor grayColor].CGColor;
    loginPwdB.layer.borderWidth = 0.5;
    loginPwdB.userInteractionEnabled = YES;
    [backgroundView addSubview:loginPwdB];
    
    
    nameTextField = [[UITextField alloc] initWithFrame:CGRectMake(10, 0 ,loginPwdB.frame.size.width-20 , SCREEN_HEIGHT*0.07)];
    nameTextField.tag = 1;
    nameTextField.placeholder = @"姓名";
    nameTextField.font = [UIFont systemFontOfSize:14];
    //writePhoneNum.backgroundColor= [UIColor whiteColor];
    [loginPwdB addSubview:nameTextField];
    nameTextField.returnKeyType=UIReturnKeyDone;
    nameTextField.delegate = self;
    
    UIImageView *loginPwdB1 = [[UIImageView alloc] initWithFrame:CGRectMake(10,loginPwdB.bottom+10, SCREEN_WIDTH-20, SCREEN_HEIGHT*0.07)];
    //loginPwdBG.image = [UIImage imageNamed:@"updatepassword_03"];
    loginPwdB1.backgroundColor = [UIColor whiteColor];
    loginPwdB1.layer.borderColor = [UIColor grayColor].CGColor;
    loginPwdB1.layer.borderWidth = 0.5;
    loginPwdB1.userInteractionEnabled = YES;
    [backgroundView addSubview:loginPwdB1];
    
    
    mobileTextField = [[UITextField alloc] initWithFrame:CGRectMake(10, 0 ,loginPwdB1.frame.size.width-20 , SCREEN_HEIGHT*0.07)];
    mobileTextField.tag = 2;
    mobileTextField.placeholder = @"手机号";
    mobileTextField.font = [UIFont systemFontOfSize:14];
    //writePhoneNum.backgroundColor= [UIColor whiteColor];
    mobileTextField.returnKeyType=UIReturnKeyDone;

    [loginPwdB1 addSubview:mobileTextField];
    mobileTextField.delegate = self;
    
    UIImageView *loginPwdBb = [[UIImageView alloc] initWithFrame:CGRectMake(10,loginPwdB1.bottom+10, SCREEN_WIDTH-20, SCREEN_HEIGHT*0.07)];
    //loginPwdBG.image = [UIImage imageNamed:@"updatepassword_03"];
    loginPwdBb.backgroundColor = [UIColor whiteColor];
    loginPwdBb.layer.borderColor = [UIColor grayColor].CGColor;
    loginPwdBb.layer.borderWidth = 0.5;
    loginPwdBb.userInteractionEnabled = YES;
    [backgroundView addSubview:loginPwdBb];
    
    
    weChatTextField = [[UITextField alloc] initWithFrame:CGRectMake(10, 0 ,loginPwdBb.frame.size.width-20 , SCREEN_HEIGHT*0.07)];
    weChatTextField.placeholder = @"微信号";
    weChatTextField.returnKeyType=UIReturnKeyDone;
    weChatTextField.font = [UIFont systemFontOfSize:14];
    //writePhoneNum.backgroundColor= [UIColor whiteColor];
    [loginPwdBb addSubview:weChatTextField];
    weChatTextField.delegate = self;
    
    
    
    shengBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    shengBtn.frame = CGRectMake(10, loginPwdBb.bottom+10, 120, 33);
    [shengBtn setBackgroundImage:[UIImage imageNamed:@"下线管理_031.jpg"] forState:UIControlStateNormal];
    shengBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [shengBtn addTarget:self action:@selector(clickSheng) forControlEvents:UIControlEventTouchUpInside];
    [backgroundView addSubview:shengBtn];
    
    label1 = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 90, 33)];
    label1.text = @"省";
    label1.textColor = [UIColor blackColor];
    label1.textAlignment = NSTextAlignmentLeft;
    label1.backgroundColor = [UIColor clearColor];
    label1.userInteractionEnabled = NO;
    [shengBtn addSubview:label1];
    
    shiBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    shiBtn.frame = CGRectMake(SCREEN_WIDTH-130, loginPwdBb.bottom+10, 120, 33);
    [shiBtn setBackgroundImage:[UIImage imageNamed:@"下线管理_031.jpg"] forState:UIControlStateNormal];
    shiBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [shiBtn addTarget:self action:@selector(clickShi) forControlEvents:UIControlEventTouchUpInside];
    [backgroundView addSubview:shiBtn];
    
    label2 = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 90, 33)];
    label2.text = @"市";
    label2.textColor = [UIColor blackColor];
    label2.textAlignment = NSTextAlignmentLeft;
    label2.backgroundColor = [UIColor clearColor];
    label2.userInteractionEnabled = NO;
    [shiBtn addSubview:label2];
    
    quBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    quBtn.frame = CGRectMake(10, shiBtn.bottom+10, 120, 33);
    [quBtn setBackgroundImage:[UIImage imageNamed:@"下线管理_031.jpg"] forState:UIControlStateNormal];
    quBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [quBtn addTarget:self action:@selector(clickQu) forControlEvents:UIControlEventTouchUpInside];
    [backgroundView addSubview:quBtn];
    
    label3 = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 90, 33)];
    label3.text = @"区";
    label3.textColor = [UIColor blackColor];
    label3.textAlignment = NSTextAlignmentLeft;
    label3.backgroundColor = [UIColor clearColor];
    label3.userInteractionEnabled = NO;
    [quBtn addSubview:label3];
    
    UIImageView *loginPwdB2 = [[UIImageView alloc] initWithFrame:CGRectMake(10,loginPwdBb.bottom+100, SCREEN_WIDTH-20, SCREEN_HEIGHT*0.09)];
    //loginPwdBG.image = [UIImage imageNamed:@"updatepassword_03"];
    loginPwdB2.backgroundColor = [UIColor whiteColor];
    loginPwdB2.layer.borderColor = [UIColor grayColor].CGColor;
    loginPwdB2.layer.borderWidth = 0.5;
    loginPwdB2.userInteractionEnabled = YES;
    [backgroundView addSubview:loginPwdB2];
    
    
    
    
    addressTextView = [[UITextView alloc] initWithFrame:CGRectMake(5, 0 ,loginPwdB2.frame.size.width-20 , SCREEN_HEIGHT*0.09)];
    addressTextView.text = @"详细地址";
    addressTextView.returnKeyType=UIReturnKeyDone;
    addressTextView.delegate = self;
    addressTextView.textColor = [UIColor lightGrayColor];
    addressTextView.font = [UIFont systemFontOfSize:14];
    //writePhoneNum.backgroundColor= [UIColor whiteColor];
    [loginPwdB2 addSubview:addressTextView];
    
    
    UIImageView *loginPwdB3 = [[UIImageView alloc] initWithFrame:CGRectMake(10,loginPwdB2.bottom+10, SCREEN_WIDTH-20, SCREEN_HEIGHT*0.07)];
    //loginPwdBG.image = [UIImage imageNamed:@"updatepassword_03"];
    loginPwdB3.backgroundColor = [UIColor whiteColor];
    loginPwdB3.layer.borderColor = [UIColor grayColor].CGColor;
    loginPwdB3.layer.borderWidth = 0.5;
    loginPwdB3.userInteractionEnabled = YES;
    [backgroundView addSubview:loginPwdB3];
    
    
    loginTextField = [[UITextField alloc] initWithFrame:CGRectMake(10, 0 ,loginPwdB3.frame.size.width-20 , SCREEN_HEIGHT*0.07)];
    loginTextField.placeholder = @"登录密码";
    loginTextField.delegate = self;
    loginTextField.returnKeyType=UIReturnKeyDone;
    loginTextField.font = [UIFont systemFontOfSize:14];
    //writePhoneNum.backgroundColor= [UIColor whiteColor];
    [loginPwdB3 addSubview:loginTextField];
    loginTextField.delegate = self;
    
    UIButton *belowBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    belowBtn.frame = CGRectMake(0.03125*SCREEN_WIDTH, loginPwdB3.bottom+15, SCREEN_WIDTH*0.9375, SCREEN_WIDTH*0.125);
    [belowBtn setBackgroundImage:[UIImage imageNamed:@"填写信息_09"] forState:UIControlStateNormal];
    [belowBtn addTarget:self action:@selector(clickRightBtn) forControlEvents:UIControlEventTouchUpInside];
    [backgroundView addSubview:belowBtn];
    
    
    
    //在imageview上添加点击手势
    UITapGestureRecognizer *singleTapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTap)];
    [singleTapGestureRecognizer setNumberOfTapsRequired:1];
    [backgroundView addGestureRecognizer:singleTapGestureRecognizer];
}
-(void)singleTap{
     [_scrollview setContentOffset:CGPointMake(0, 0) animated:YES];
    _picker.hidden = YES;
    zPickerBtn.hidden = YES;
    [nameTextField resignFirstResponder];
    [mobileTextField resignFirstResponder];
    [weChatTextField resignFirstResponder];
    [loginTextField resignFirstResponder];
    [addressTextView resignFirstResponder];
   
}
#pragma -mark 用来监视键盘的退出
- (void)keyboardWillHide{
 [_scrollview setContentOffset:CGPointMake(0, 0) animated:YES];
}

- (BOOL)textViewShouldBeginEditing:(UITextView *)textView{

    [_scrollview setContentOffset:CGPointMake(0, 200) animated:YES];
    return YES;
}
#pragma mark - UItextView delegate
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
    if ([text isEqualToString:@"\n"])
    {
        [textView resignFirstResponder]; return NO;
    }
    return YES; 
}
#pragma -mark UIPickerView 的代理

-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
    return 1;
}
-(NSInteger) pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
    return [zProvince count];
}
-(NSString*) pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
    if (_select == 0) {
        if (row == 0) {
            label1.text = [[zProvince objectAtIndex:zProvinceIndex] objectForKey:@"ProvinceName"];
            zPID =[NSString stringWithFormat:@"%@",[[zProvince objectAtIndex:zProvinceIndex] objectForKey:@"ProvinceID"]];
            
        }

        return [[zProvince objectAtIndex:row]objectForKey:@"ProvinceName"];
        
    }else if (_select == 1){
        if (row == 0) {
            label2.text = [[zProvince objectAtIndex:zCityIndex] objectForKey:@"CityName"];
            zCID =[NSString stringWithFormat:@"%@",[[zProvince objectAtIndex:zCityIndex] objectForKey:@"CityID"]];
            
        }

        return [[zProvince objectAtIndex:row]objectForKey:@"CityName"];
        
    }else{
        if (row == 0) {
            label3.text = [[zProvince objectAtIndex:zZhengJianIndex] objectForKey:@"CountyName"];
            zzCID =[NSString stringWithFormat:@"%@",[[zProvince objectAtIndex:zZhengJianIndex] objectForKey:@"CountyID"]];
            
        }

        return [[zProvince objectAtIndex:row]objectForKey:@"CountyName"];
        
    }
}

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
    if ([textField isEqual:addressTextView] || [textField isEqual:loginTextField]) {

      [_scrollview setContentOffset:CGPointMake(0, 200) animated:YES];
    }
    return YES;
}
#pragma mark - UITextField delegate
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder];
     [_scrollview setContentOffset:CGPointMake(0, 0) animated:YES];
    return  YES;
}
#pragma -mark 选中省市区的代理
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
    if (_select == 0) {
        zIndex = row;
    }else if (_select == 1){
        zCityIndex = row;
    }else{
        zZhengJianIndex = row;
    }
    
//    switch (_select) {
//        case Province://选择省
//            //[_addressView.provinceBut setTitle:pickerArray[row] forState:UIControlStateNormal];
//            NSLog(@"%ld",(long)row);
//            zProvinceIndex = row;
//            label1.text = [[zProvince objectAtIndex:row] objectForKey:@"ProvinceName"];
//            zPID =[NSString stringWithFormat:@"%@",[[zProvince objectAtIndex:row] objectForKey:@"ProvinceID"]];
//            _picker.hidden = YES;
//            label2.text = @"市";
//            label3.text = @"区";
//            zCID = @"0";
//            zzCID = @"0";
//            zCityIndex = 0;
//            zZhengJianIndex = 0;
//            break;
//        case City://市
//            //[_addressView.cityBut setTitle:pickerArray[row] forState:UIControlStateNormal];
//            zCityIndex = row;
//
//            label2.text = [[zProvince objectAtIndex:row] objectForKey:@"CityName"];
//            zCID = [[zProvince objectAtIndex:row] objectForKey:@"CityID"];
//            _picker.hidden = YES;
//            label3.text = @"区";
//            zzCID = @"0";
//            zZhengJianIndex = 0;
//            break;
//        case Qu: //区
//            zZhengJianIndex = row;
//            // [_addressView.quBut setTitle:pickerArray[row] forState:UIControlStateNormal];
//            label3.text = [[zProvince objectAtIndex:row] objectForKey:@"CountyName"];
//            zzCID = [[zProvince objectAtIndex:row] objectForKey:@"CountyID"];
//            _picker.hidden = YES;
//            break;
//    }
}

#pragma mark - 点击省
-(void)clickSheng{
    [nameTextField resignFirstResponder];
    [mobileTextField resignFirstResponder];
    [weChatTextField resignFirstResponder];
    [loginTextField resignFirstResponder];
    [addressTextView resignFirstResponder];
    if (_picker) {
        YoungAllData *data = [[YoungAllData alloc]init];
        data.delegate=self;
        [data gainProvince];
        
    }else{
        zProvince = [[NSMutableArray alloc]init];
        
        YoungAllData *data = [[YoungAllData alloc]init];
        data.delegate=self;
        [data gainProvince];
        
        //创建省市区选择框
        _picker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT - 200, SCREEN_WIDTH, 200)];
        _picker.backgroundColor = LineColor;
        _picker.layer.borderColor = BackColor.CGColor;
        _picker.layer.borderWidth = 1.0;
        _picker.dataSource = self;
        _picker.delegate = self;
        _picker.hidden = NO;
        [self.view addSubview:_picker];
        
        _select = 0;
        
        if (zPickerBtn) {
            zPickerBtn.hidden = NO;
        }else{
            zPickerBtn = [UIButton buttonWithType:UIButtonTypeCustom];
            [zPickerBtn setBackgroundColor:[UIColor blackColor]];
            zPickerBtn.alpha = 0.4;
            zPickerBtn.frame = CGRectMake(0, SCREEN_HEIGHT - 123.5, SCREEN_WIDTH, 26);
            [zPickerBtn addTarget:self action:@selector(clickBtn) forControlEvents:UIControlEventTouchUpInside];
            [self.view addSubview:zPickerBtn];
        }

    }
    
}
#pragma mark - 省回调
-(void)province:(NSDictionary *)sign{
    if ([[sign objectForKey:@"status"] isEqualToString:@"success"]) {
    _picker.hidden = NO;
    _select = 0;
    NSLog(@"%@",sign);
    zProvince = [[NSMutableArray alloc]initWithArray:[sign objectForKey:@"data"]];
    [_picker reloadAllComponents];
    if (zProvinceIndex==0) {
        [_picker selectRow:0 inComponent:0 animated:NO];
    }else{
        [_picker selectRow:zProvinceIndex inComponent:0 animated:NO];
    }
    zPickerBtn.hidden = NO;
    }else{
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:[sign objectForKey:@"reason"] delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
    }
}
#pragma mark - 省回调失败
-(void)requistFail{
    [GMDCircleLoader hideFromView:self.view animated:YES];
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"网络异常,无法加载数据" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    [alert show];
}
#pragma mark - 点击市
-(void)clickShi{
    [nameTextField resignFirstResponder];
    [mobileTextField resignFirstResponder];
    [weChatTextField resignFirstResponder];
    [loginTextField resignFirstResponder];
    [addressTextView resignFirstResponder];
    if ([zPID isEqualToString:@"0"]) {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"请先选择省" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
    }else{
        YoungAllData *data = [[YoungAllData alloc]init];
        data.delegate=self;
        [data gainCity:zPID];
        
        
        //[_picker reloadAllComponents];
        
        _select = 1;
    }
}
#pragma mark -市回调
-(void)city:(NSDictionary *)sign{
    if ([[sign objectForKey:@"status"] isEqualToString:@"success"]) {
    zProvince = [[NSMutableArray alloc]initWithArray:[sign objectForKey:@"data"]];
    [_picker reloadAllComponents];
    _picker.hidden = NO;
    if (zCityIndex==0) {
        [_picker selectRow:0 inComponent:0 animated:NO];
    }else{
        [_picker selectRow:zCityIndex inComponent:0 animated:NO];
    }
    zPickerBtn.hidden = NO;
    }else{
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:[sign objectForKey:@"reason"] delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];

    }
}
#pragma mark - 点击区
-(void)clickQu{
    [nameTextField resignFirstResponder];
    [mobileTextField resignFirstResponder];
    [weChatTextField resignFirstResponder];
    [loginTextField resignFirstResponder];
    [addressTextView resignFirstResponder];
    if ([zPID isEqualToString:@"0"]) {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"请先选择省" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
    }else if([zCID isEqualToString:@"0"]){
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"请先选择市" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
    }else{
        
        
        YoungAllData *data = [[YoungAllData alloc]init];
        data.delegate=self;
        [data gainCountry:zCID];
        
        _select = 2;
    }
}
#pragma mark - 区回调
-(void)country:(NSDictionary *)sign{
    if ([[sign objectForKey:@"status"] isEqualToString:@"success"]) {
    zProvince = [[NSMutableArray alloc]initWithArray:[sign objectForKey:@"data"]];
    [_picker reloadAllComponents];
    _picker.hidden = NO;
    if (zZhengJianIndex==0) {
        [_picker selectRow:0 inComponent:0 animated:NO];
    }else{
        [_picker selectRow:zZhengJianIndex inComponent:0 animated:NO];
    }
    zPickerBtn.hidden = NO;
    }else{
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:[sign objectForKey:@"reason"] delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
    }
}

#pragma mark - 立即申请
-(void)clickRightBtn{

    if ([nameTextField.text isEqualToString:@""]) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"请输入姓名" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
        return;
    }
    if ([mobileTextField.text isEqualToString:@""]) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"请输入电话号码" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
        return;
    }
    if ([weChatTextField.text isEqualToString:@""]) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"请输入微信号" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
        return;
    }
    if ([label1.text isEqualToString:@""]) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"请选择省市区" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
        return;
    }
    if ([label2.text isEqualToString:@""]) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"请选择省市区" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
        return;
    }
    if ([label3.text isEqualToString:@"区"]) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"请选择省市区" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
        return;
    }
    if ([addressTextView.text isEqualToString:@""]) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"请输入详细地址" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
        return;
    }
    if ([loginTextField.text isEqualToString:@""]) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"请输入登陆密码" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
        return;
    }


    YoungAllData *data = [[YoungAllData alloc]init];
    data.delegate= self;
    [GMDCircleLoader setOnView:self.view withTitle:@"申请中···" animated:YES];
    [data gainRecommend:[[NSUserDefaults standardUserDefaults] objectForKey:@"userID"] andRealName:nameTextField.text andMobileNumber:mobileTextField.text andLoginPass:loginTextField.text andProvinceID:zPID andCityID:zCID andCountyID:zzCID andAddress:addressTextView.text andLevelID:levelNumber andWeChat:weChatTextField.text];
    
}

#pragma mark - UIpickerView 选择Btn
-(void)clickBtn{

    UIButton *btn = (UIButton *)[self.view viewWithTag:401];
    UIButton *btn1 = (UIButton *)[self.view viewWithTag:402];
    UIButton *btn2 = (UIButton *)[self.view viewWithTag:403];
    switch (_select) {
        case Province://选择省
            //[_addressView.provinceBut setTitle:pickerArray[row] forState:UIControlStateNormal];
            zProvinceIndex = zIndex;
            label1.text = [[zProvince objectAtIndex:zProvinceIndex] objectForKey:@"ProvinceName"];
            zPID =[NSString stringWithFormat:@"%@",[[zProvince objectAtIndex:zProvinceIndex] objectForKey:@"ProvinceID"]];                     _picker.hidden = YES;
            [btn1 setTitle:@"开户行所在的市" forState:UIControlStateNormal];
            [btn1 setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
            _picker.hidden = YES;
            label2.text = @"市";
            label3.text = @"区";
            zCID = @"0";
            zzCID = @"0";
            zCityIndex = 0;
            zZhengJianIndex = 0;
            break;
            
        case City://市
            //[_addressView.cityBut setTitle:pickerArray[row] forState:UIControlStateNormal];
            
            label2.text = [[zProvince objectAtIndex:zCityIndex] objectForKey:@"CityName"];
            zCID = [[zProvince objectAtIndex:zCityIndex] objectForKey:@"CityID"];
            _picker.hidden = YES;
            label3.text = @"区";
            zzCID = @"0";
            zZhengJianIndex = 0;
            
            break;
        case Qu://市
            // [_addressView.quBut setTitle:pickerArray[row] forState:UIControlStateNormal];
            label3.text = [[zProvince objectAtIndex:zZhengJianIndex] objectForKey:@"CountyName"];
            zzCID = [[zProvince objectAtIndex:zZhengJianIndex] objectForKey:@"CountyID"];
            _picker.hidden = YES;
            
            break;
            
    }
    zPickerBtn.hidden = YES;
}

#pragma mark -申请回调
-(void)recommend:(NSDictionary *)sign{
    [GMDCircleLoader hideFromView:self.view animated:YES];
    if ([[sign objectForKey:@"status"] isEqualToString:@"success"]) {
    ApplyForSuccessController *apply = [[ApplyForSuccessController alloc]init];
    [self.navigationController pushViewController:apply animated:YES];
    }else{
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:[sign objectForKey:@"reason"] delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - UItextView delegate
-(void)textViewDidBeginEditing:(UITextView *)textView{
    if ([addressTextView.text isEqualToString:@"详细地址"]) {
        addressTextView.text = @"";
    }
}
-(void)textViewDidEndEditing:(UITextView *)textView{
    if (addressTextView.text.length<1) {
        addressTextView.text = @"详细地址";
    }
}
/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
